
<template>
    <div class="channelShopContainer">
        <div class="infolist">

          <div class="headerSection">
            <split-vertical title="渠道商品信息"></split-vertical>
            <v-form :formProps="searchForm" ref="form"
                    v-on:handleReset="handleReset"
                    v-on:coverFormData="coverFormData">
            </v-form>
          </div>
          <div class="stand">
            <div style="line-height:50px;margin-left:10px;">
              <v-button :operationBtnArray="operationBtnArray" v-on:handleSearchTopBtn="handleSearchTopBtn"></v-button>
            </div>
            <div style="margin:0 10px;">
              <v-table :tableParams="tableParams" v-on:handleOperation="handleOperation"></v-table>
            </div>
          </div>
            <div class="block">
                <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="pageIndex"
                    :page-sizes="[10]"
                    :page-size="10"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageCount">
                </el-pagination>
            </div>
        </div>
        <!-- 编辑信息 -->
        <set-shop v-if="show2" :add='add' @closeDialog='closeDialog'></set-shop>
        <!-- 创建信息 -->
        <shop-info v-if="show" @closeDialog='closeDialog'></shop-info>
    </div>
</template>
<script>
import VTable from "components/common/PageTable/VTable"
import shopInfo from 'components/base/ChannelShop/ShopInfo'
import setShop from 'components/base/ChannelShop/SetShop.vue'
import SplitVertical from "components/common/SplitVertical"
import VForm from "components/common/VForm"
import VButton from "components/common/VButton"
export default {
    inject:['reload'],
    data(){
        return{
            channelInfo:[],
            pageCount: 0,
            pageIndex:1,
            pageSize:10,
            show:false,//控制创建公司信息的显示
            show2:false,//控制编辑公司信息的显示
            add:{},
            //v-model
            channelName:'',
            channelProductName:'',
            channelProductNo:'',
            searchForm: {
              col: 3,
              labelWidth: '110px',
              submitBtn: {
                text: '搜索'
              },
              formItemArray: [{
                label: '渠道商品名称',
                prop: 'channelProductName',
                placeholder: "请输入",
                value: ''
              },{
                label: '渠道名称',
                prop: 'channelName',
                placeholder: "请输入货号",
                itemType: 'select',
                options: [],
                value: ''
              },  {
                label: '渠道商品编号',
                placeholder: "请输入",
                prop: 'channelProductNo',
                value: ''
              }],
            },
            operationBtnArray: [{
              text: '刷新',
              icon:'el-icon-refresh',
              show: true,
              type: 'primary',
              methodName: 'refresh',
            }, {
              text: '新增',
              icon:'el-icon-plus',
              show: true,
              type: 'success',
              methodName: 'add',
            }],
            tableParams:{
                dataArray:[],
                showMultiSelection:false,
                columnArray:[
                    {label: '授权产品ID', prop: 'sqproductId',width:'100',sortable: false},
                    {label: '渠道名称', prop: 'channelName',width:'150',  sortable: false},
                    {label: '渠道商品名称', prop: 'channelProductName',  sortable: false,width:'120'},
                    {label: '渠道商品编号', prop: 'channelProductNo', width:'120',sortable: false},
                    {label: '渠道售价(￥)', prop: 'channelPrice',width:'110',sortable: false},
                    {label: '商品sku', prop: 'sku',sortable: false,},
                    {label: '积分佣金(%)', prop: 'integral',width:'100',sortable: false},
                    {label: '全额佣金(%)', prop: 'commission',width:'100',sortable: false},
                    {label: '创建时间', prop: 'createtime',width:'100',sortable: false},
                    {label: '录入人', prop: 'name',width:'100',sortable: false}
                ],
                rowHandle:{
                    view:{
                        show:false
                    }
                }
            },
          searchCondition:{}
        }
    },
    created(){
      this.init()
    },
    methods:{
        init(){
           this.listVal()
           this.getchannelInfomation()
        },
        handleSearchTopBtn(methodName) {
          if (methodName === "refresh") {
            this.refresh();
          } else {
            this.create();
          }
        },
        handleReset(formName) {
          this.$refs.form.resetForm(formName);
        },
        coverFormData(data) {
          this.searchCondition = data;
          this.query()
        },
        handleOperation(rowIndex, row, methodName) {
            this.id=row.id
            if(methodName == "update"){
                this.showTip=true
                this.edit()
            }else if(methodName == "delete"){
                this.delChannelShop()
            }
        },
        getchannelInfomation(){
            let parmas={
                pageIndex:1,
                pageSize:10
            }
            let success=data=>{
                if(data.code=='OK'){
                  this.searchForm.formItemArray.forEach(item => {
                    if (item.prop === 'channelName') {
                      item.options = this.buildExceptKeyAndValue(data.data, "channelName", "channelName", "label", "value");
                    }
                  })
                } else{
                    this.$message.error(data.msg)
                }
            }
            this.api.channelList(parmas,success)
        },
        //刷新
        refresh(){
            this.listVal()
        },
        // 关闭控制编辑公司信息的显示弹窗
        closeDialog(){
            this.show2 = false;
            this.show = false;
        },
        //初始化渠道商品信息的list表格
        listVal(){
            let parmas={
                pageIndex:1,
                pageSize:10
            }
            let success=data=>{
                if(data.code=='OK'){
                    this.tableParams.dataArray =data.data
                    data.data.forEach(element => {
                        element.createtime=element.createtime.substr(0,10)
                    });
                    this.pageCount=data.pageCount
                } else{
                    this.$message.error(data.msg)
                }
            }
            this.api.channelProductList(parmas,success)
        },
        //编辑表格信息
        edit(){
            this.show2=true
            let parmas={
               id:this.id
            }
            let success=data=>{
                if(data.code=='OK'){
                    this.add=data.data
                }else{
                    this.$message.error(data.msg)
                }
            }
            this.api.channelProductInfoGetone(parmas,success)
        },
        //查询
        query(){
            let param = this.searchCondition;
            if (!param.pageIndex || !param.pageSize) {
              param['pageIndex'] = this.pageIndex;
              param['pageSize'] = this.pageSize;
            }
            let success = data => {
              if (data.code === 'OK') {
                this.pageCount = data.pageCount;
                this.tableParams.dataArray=data.data
              } else {
                this.$message.error(data.msg);
              }
            };
            this.api.channelProductList(param,success)
        },
        //删除表格信息
        delChannelShop(){
            this.$confirm('是否删除该消息, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            center: true
            }).then(() => {
                let parmas={
                    id:this.id
                }
                let success=data=>{
                    if(data.code=='OK'){
                        this.reload()
                        this.$message({
                        type: 'success',
                        message: '删除成功!'
                     });
                    }
                }
                this.api.channelProductInfoDelete(parmas,success)

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消删除'
                });
            });
        },
        //重置清空
        reset(){
            this.channelName='',
            this.channelProductName='',
            this.channelProductNo=""
        },
        //创建渠道信息
        create(){
            this.show=!this.show;
        },
        //当前页
        handleCurrentChange(val) {
          this.searchCondition['pageIndex'] = val;
          this.query()
        }
    },
    components:{
        shopInfo, setShop, VTable,VForm, VButton, SplitVertical
    }
}
</script>
<style>
.content .el-table__header-wrapper{
    background:#eee;
    font-size: 16px;
}
</style>
<style lang="scss" scoped>
.channelShopContainer{
    width: 100%;
   .infolist {
     height: auto;
     .headerSection{
       background:#fff;
       height:140px;
       padding:0 10px;
       border-left: 2px solid #e8e8e8;
       border-right: 2px solid #e8e8e8;
       border-bottom: 2px solid #e8e8e8;
     }
     .block {
       padding: 10px 0;
       text-align: right;
     }
   }
}
</style>
